import bus from './bus'
const io = require('socket.io-client')

export default function () {
  const socket = io.connect('http://localhost:3000')

  socket.on('getQuestionUpdate', () => {
    console.log('服务端发来消息');
    bus.emit('questionUpdate');
  })

  function sendQuestionUpdate () {
    socket.emit('sendQuestionUpdate')
  }

  socket.on('getCommunicateUpdate', () => {
    console.log('服务端发来消息');
    bus.emit('communicateUpdate');
  })

  function sendCommunicateUpdate () {
    socket.emit('sendCommunicateUpdate')
  }


  return {
    sendQuestionUpdate,
    sendCommunicateUpdate,
  }
}
